//
//  User.m
//  TuiTe
//
//  Created by 张 霄鹤 on 10-3-12.
//  Copyright 2010 xhzhang. All rights reserved.
//

#import "User.h"


@implementation User

@dynamic uid;
@dynamic name;
@dynamic screen_name;
@dynamic location;
@dynamic udescription;
@dynamic profile_image_url;
@dynamic url;
@dynamic isProtected;
@dynamic followers_count;
@dynamic friends_count;
@dynamic favourites_count;
@dynamic verified;
@dynamic statuses_count;

@synthesize created_at;
@synthesize profile_background_image_url;
@synthesize geo_enabled;
@synthesize following;
@synthesize profile_background_color;
@synthesize profile_text_color;
@synthesize profile_link_color;
@synthesize profile_sidebar_fill_color;
@synthesize profile_sidebar_border_color;


- (id)init{
	if(self = [super init]){
	}
	return self;
}

- (void)parse:(Element *)el{
	Node *nd = [el getChildByName:@"id"];
	if(nd){
		self.uid = [[nd getChildByName:@"#TEXT"] getValue];
	}
	
	nd = [el getChildByName:@"name"];
	if(nd){
		// self.name = [[nd getChildByName:@"#TEXT"] getValue];
		Element *exx = (Element *)nd;
		NSArray *es = [exx getElementsByName:@"#TEXT"];
		if(es){
			NSMutableString *str = [[NSMutableString alloc] init];
			for(Node *dn in es){
				[str appendString:[dn getValue]];
			}
			self.name = str;
			[str release];
		}
	}
	
	nd = [el getChildByName:@"screen_name"];
	if(nd){
		// self.screen_name = [[nd getChildByName:@"#TEXT"] getValue];
		Element *exx = (Element *)nd;
		NSArray *es = [exx getElementsByName:@"#TEXT"];
		if(es){
			NSMutableString *str = [[NSMutableString alloc] init];
			for(Node *dn in es){
				[str appendString:[dn getValue]];
			}
			self.screen_name = str;
			[str release];
		}
	}
	
	nd = [el getChildByName:@"location"];
	if(nd){
		self.location = [[nd getChildByName:@"#TEXT"] getValue];
	}
	
	nd = [el getChildByName:@"description"];
	if(nd){
		// self.udescription = [[nd getChildByName:@"#TEXT"] getValue];
		Element *exx = (Element *)nd;
		NSArray *es = [exx getElementsByName:@"#TEXT"];
		if(es){
			NSMutableString *str = [[NSMutableString alloc] init];
			for(Node *dn in es){
				[str appendString:[dn getValue]];
			}
			self.udescription = str;
			[str release];
		}
	}
	
	nd = [el getChildByName:@"profile_image_url"];
	if(nd){
		self.profile_image_url = [[nd getChildByName:@"#TEXT"] getValue];
	}
	
	nd = [el getChildByName:@"url"];
	if(nd){
		self.url = [[nd getChildByName:@"#TEXT"] getValue];
	}
	
	nd = [el getChildByName:@"protected"];
	if(nd){
		NSString *ns = [[nd getChildByName:@"#TEXT"] getValue];
		NSNumber *n1 = [[NSNumber alloc] initWithBool:[ns isEqualToString:@"true"]];
		self.isProtected = n1;
		[n1 release];
	}
	
	nd = [el getChildByName:@"followers_count"];
	if(nd){
		NSString *ns = [[nd getChildByName:@"#TEXT"] getValue];
		NSNumber *n1 = [[NSNumber alloc] initWithInt:[ns intValue]];
		self.followers_count = n1;
		[n1 release];
	}
	
	nd = [el getChildByName:@"profile_background_color"];
	if(nd){
		NSString *ns = [[nd getChildByName:@"#TEXT"] getValue];
		self.profile_background_color = [ns intValue];
	}
	nd = [el getChildByName:@"profile_text_color"];
	if(nd){
		NSString *ns = [[nd getChildByName:@"#TEXT"] getValue];
		self.profile_text_color = [ns intValue];
	}
	nd = [el getChildByName:@"profile_link_color"];
	if(nd){
		NSString *ns = [[nd getChildByName:@"#TEXT"] getValue];
		self.profile_link_color = [ns intValue];
	}
	nd = [el getChildByName:@"profile_sidebar_fill_color"];
	if(nd){
		NSString *ns = [[nd getChildByName:@"#TEXT"] getValue];
		self.profile_sidebar_fill_color = [ns intValue];
	}
	nd = [el getChildByName:@"profile_sidebar_border_color"];
	if(nd){
		NSString *ns = [[nd getChildByName:@"#TEXT"] getValue];
		self.profile_sidebar_border_color = [ns intValue];
	}
	nd = [el getChildByName:@"friends_count"];
	if(nd){
		NSString *ns = [[nd getChildByName:@"#TEXT"] getValue];
		NSNumber *n1 = [[NSNumber alloc] initWithInt:[ns intValue]];
		self.friends_count = n1;
		[n1 release];
	}
	
	nd = [el getChildByName:@"created_at"];
	if(nd){
		self.created_at = [[nd getChildByName:@"#TEXT"] getValue];
	}
	
	nd = [el getChildByName:@"favourites_count"];
	if(nd){
		NSString *ns = [[nd getChildByName:@"#TEXT"] getValue];
		NSNumber *n1 = [[NSNumber alloc] initWithInt:[ns intValue]];
		self.favourites_count = n1;
		[n1 release];
	}
	
	nd = [el getChildByName:@"profile_background_image_url"];
	if(nd){
		self.profile_background_image_url = [[nd getChildByName:@"#TEXT"] getValue];
	}
	
	nd = [el getChildByName:@"geo_enabled"];
	if(nd){
		NSString *ns = [[nd getChildByName:@"#TEXT"] getValue];
		self.geo_enabled = [ns isEqualToString:@"true"];
	}
	
	nd = [el getChildByName:@"verified"];
	if(nd){
		NSString *ns = [[nd getChildByName:@"#TEXT"] getValue];
		NSNumber *n1 = [[NSNumber alloc] initWithBool:[ns isEqualToString:@"true"]];
		self.verified = n1; // [NSNumber numberWithBool:[ns isEqualToString:@"true"]];
		[n1 release];
	}
	
	nd = [el getChildByName:@"statuses_count"];
	if(nd){
		NSString *ns = [[nd getChildByName:@"#TEXT"] getValue];
		NSNumber *n1 = [[NSNumber alloc] initWithInt:[ns intValue]];
		self.statuses_count = n1; // [NSNumber numberWithInt:[ns intValue]];
		[n1 release];
	}
	
}

- (NSNumber *)favourites_count 
{
    NSNumber * tmpValue;
    
    [self willAccessValueForKey:@"favourites_count"];
    tmpValue = [self primitiveValueForKey:@"favourites_count"];
    [self didAccessValueForKey:@"favourites_count"];
    
    return tmpValue;
}

- (void)setFavourites_count:(NSNumber *)value 
{
    [self willChangeValueForKey:@"favourites_count"];
    [self setPrimitiveValue:value forKey:@"favourites_count"];
    [self didChangeValueForKey:@"favourites_count"];
}

- (BOOL)validateFavourites_count:(id *)valueRef error:(NSError **)outError 
{
    // Insert custom validation logic here.
    return YES;
}

- (NSNumber *)followers_count 
{
    NSNumber * tmpValue;
    
    [self willAccessValueForKey:@"followers_count"];
    tmpValue = [self primitiveValueForKey:@"followers_count"];
    [self didAccessValueForKey:@"followers_count"];
    
    return tmpValue;
}

- (void)setFollowers_count:(NSNumber *)value 
{
    [self willChangeValueForKey:@"followers_count"];
    [self setPrimitiveValue:value forKey:@"followers_count"];
    [self didChangeValueForKey:@"followers_count"];
}

- (BOOL)validateFollowers_count:(id *)valueRef error:(NSError **)outError 
{
    // Insert custom validation logic here.
    return YES;
}

- (NSNumber *)friends_count 
{
    NSNumber * tmpValue;
    
    [self willAccessValueForKey:@"friends_count"];
    tmpValue = [self primitiveValueForKey:@"friends_count"];
    [self didAccessValueForKey:@"friends_count"];
    
    return tmpValue;
}

- (void)setFriends_count:(NSNumber *)value 
{
    [self willChangeValueForKey:@"friends_count"];
    [self setPrimitiveValue:value forKey:@"friends_count"];
    [self didChangeValueForKey:@"friends_count"];
}

- (BOOL)validateFriends_count:(id *)valueRef error:(NSError **)outError 
{
    // Insert custom validation logic here.
    return YES;
}

- (NSNumber *)isProtected 
{
    NSNumber * tmpValue;
    
    [self willAccessValueForKey:@"isProtected"];
    tmpValue = [self primitiveValueForKey:@"isProtected"];
    [self didAccessValueForKey:@"isProtected"];
    
    return tmpValue;
}

- (void)setIsProtected:(NSNumber *)value 
{
    [self willChangeValueForKey:@"isProtected"];
    [self setPrimitiveValue:value forKey:@"isProtected"];
    [self didChangeValueForKey:@"isProtected"];
}

- (BOOL)validateIsProtected:(id *)valueRef error:(NSError **)outError 
{
    // Insert custom validation logic here.
    return YES;
}

- (NSString *)location 
{
    NSString * tmpValue;
    
    [self willAccessValueForKey:@"location"];
    tmpValue = [self primitiveValueForKey:@"location"];
    [self didAccessValueForKey:@"location"];
    
    return tmpValue;
}

- (void)setLocation:(NSString *)value 
{
    [self willChangeValueForKey:@"location"];
    [self setPrimitiveValue:value forKey:@"location"];
    [self didChangeValueForKey:@"location"];
}

- (BOOL)validateLocation:(id *)valueRef error:(NSError **)outError 
{
    // Insert custom validation logic here.
    return YES;
}

- (NSString *)name 
{
    NSString * tmpValue;
    
    [self willAccessValueForKey:@"name"];
    tmpValue = [self primitiveValueForKey:@"name"];
    [self didAccessValueForKey:@"name"];
    
    return tmpValue;
}

- (void)setName:(NSString *)value 
{
    [self willChangeValueForKey:@"name"];
    [self setPrimitiveValue:value forKey:@"name"];
    [self didChangeValueForKey:@"name"];
}

- (BOOL)validateName:(id *)valueRef error:(NSError **)outError 
{
    // Insert custom validation logic here.
    return YES;
}

- (NSString *)profile_image_url 
{
    NSString * tmpValue;
    
    [self willAccessValueForKey:@"profile_image_url"];
    tmpValue = [self primitiveValueForKey:@"profile_image_url"];
    [self didAccessValueForKey:@"profile_image_url"];
    
    return tmpValue;
}

- (void)setProfile_image_url:(NSString *)value 
{
    [self willChangeValueForKey:@"profile_image_url"];
    [self setPrimitiveValue:value forKey:@"profile_image_url"];
    [self didChangeValueForKey:@"profile_image_url"];
}

- (BOOL)validateProfile_image_url:(id *)valueRef error:(NSError **)outError 
{
    // Insert custom validation logic here.
    return YES;
}

- (NSString *)screen_name 
{
    NSString * tmpValue;
    
    [self willAccessValueForKey:@"screen_name"];
    tmpValue = [self primitiveValueForKey:@"screen_name"];
    [self didAccessValueForKey:@"screen_name"];
    
    return tmpValue;
}

- (void)setScreen_name:(NSString *)value 
{
    [self willChangeValueForKey:@"screen_name"];
    [self setPrimitiveValue:value forKey:@"screen_name"];
    [self didChangeValueForKey:@"screen_name"];
}

- (BOOL)validateScreen_name:(id *)valueRef error:(NSError **)outError 
{
    // Insert custom validation logic here.
    return YES;
}

- (NSNumber *)statuses_count 
{
    NSNumber * tmpValue;
    
    [self willAccessValueForKey:@"statuses_count"];
    tmpValue = [self primitiveValueForKey:@"statuses_count"];
    [self didAccessValueForKey:@"statuses_count"];
    
    return tmpValue;
}

- (void)setStatuses_count:(NSNumber *)value 
{
    [self willChangeValueForKey:@"statuses_count"];
    [self setPrimitiveValue:value forKey:@"statuses_count"];
    [self didChangeValueForKey:@"statuses_count"];
}

- (BOOL)validateStatuses_count:(id *)valueRef error:(NSError **)outError 
{
    // Insert custom validation logic here.
    return YES;
}

- (NSString *)udescription 
{
    NSString * tmpValue;
    
    [self willAccessValueForKey:@"udescription"];
    tmpValue = [self primitiveValueForKey:@"udescription"];
    [self didAccessValueForKey:@"udescription"];
    
    return tmpValue;
}

- (void)setUdescription:(NSString *)value 
{
    [self willChangeValueForKey:@"udescription"];
    [self setPrimitiveValue:value forKey:@"udescription"];
    [self didChangeValueForKey:@"udescription"];
}

- (BOOL)validateUdescription:(id *)valueRef error:(NSError **)outError 
{
    // Insert custom validation logic here.
    return YES;
}

- (NSString *)uid 
{
    NSString * tmpValue;
    
    [self willAccessValueForKey:@"uid"];
    tmpValue = [self primitiveValueForKey:@"uid"];
    [self didAccessValueForKey:@"uid"];
    
    return tmpValue;
}

- (void)setUid:(NSString *)value 
{
    [self willChangeValueForKey:@"uid"];
    [self setPrimitiveValue:value forKey:@"uid"];
    [self didChangeValueForKey:@"uid"];
}

- (BOOL)validateUid:(id *)valueRef error:(NSError **)outError 
{
    // Insert custom validation logic here.
    return YES;
}

- (NSString *)url 
{
    NSString * tmpValue;
    
    [self willAccessValueForKey:@"url"];
    tmpValue = [self primitiveValueForKey:@"url"];
    [self didAccessValueForKey:@"url"];
    
    return tmpValue;
}

- (void)setUrl:(NSString *)value 
{
    [self willChangeValueForKey:@"url"];
    [self setPrimitiveValue:value forKey:@"url"];
    [self didChangeValueForKey:@"url"];
}

- (BOOL)validateUrl:(id *)valueRef error:(NSError **)outError 
{
    // Insert custom validation logic here.
    return YES;
}

- (NSNumber *)verified 
{
    NSNumber * tmpValue;
    
    [self willAccessValueForKey:@"verified"];
    tmpValue = [self primitiveValueForKey:@"verified"];
    [self didAccessValueForKey:@"verified"];
    
    return tmpValue;
}

- (void)setVerified:(NSNumber *)value 
{
    [self willChangeValueForKey:@"verified"];
    [self setPrimitiveValue:value forKey:@"verified"];
    [self didChangeValueForKey:@"verified"];
}

- (BOOL)validateVerified:(id *)valueRef error:(NSError **)outError 
{
    // Insert custom validation logic here.
    return YES;
}


- (void)addTweetsObject:(Tweet *)value 
{    
    NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1];
    
    [self willChangeValueForKey:@"tweets" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects];
    [[self primitiveValueForKey:@"tweets"] addObject:value];
    [self didChangeValueForKey:@"tweets" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects];
    
    [changedObjects release];
}

- (void)removeTweetsObject:(Tweet *)value 
{
    NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1];
    
    [self willChangeValueForKey:@"tweets" withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects];
    [[self primitiveValueForKey:@"tweets"] removeObject:value];
    [self didChangeValueForKey:@"tweets" withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects];
    
    [changedObjects release];
}



- (void)dealloc{
	
	[uid release];
	[name release];
	[screen_name release];
	[location release];
	[udescription release];
	[profile_image_url release];
	[url release];
	[created_at release];
	[profile_background_image_url release];

	[super dealloc];
}

@end
